<template>
  <div class="app-container">
    <el-form :inline="true">
      <el-form-item>
        <el-button
          icon="el-icon-plus"
          type="primary"
          @click="gotoManage"
        >{{ $t('manage') }}
        </el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tagList"
      style="width: 100%"
    >
      <el-table-column
        prop="name"
        :label="$t('name')"
      />
      <el-table-column
        :label="$t('time')"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span style="margin-left: 13px">{{
            formatDate(scope.row.createdDate)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('function')" width="150">
        <template slot-scope="scope">
          <el-button
            style="color: #f56c6c"
            type="text"
            icon="el-icon-delete"
            @click="del(scope.row)"
          >{{ $t('delete') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>
<script>
import {
  formatDate
} from '@/util/common'
import {
  listTag
} from '@/api/iot/iotTagApi'

export default {
  name: 'TagModel',
  data() {
    return {
      tagList: [],
      tag: {}
    }
  }, created() {
    this.listTag()
  },
  methods: {
    formatDate(time) {
      return formatDate(this, time)
    },
    gotoManage() {
      this.$router.push({
        path: '/tag/manage'
      })
    },
    listTag() {
      listTag({}).then(res => {
        const { code, data } = res
        if (code === '200') {
          this.tagList = data
        } else {
          this.tagList = []
        }
      })
    }
  }
}
</script>


